#encoding:utf-8

from pojo.entity.BaseEntity import BaseEntity

class Share(BaseEntity):
    id=None
    realTransactionId = None
    tradeDate=None

    market=None
    symbol=None
    sename=None
    seat=None

    volBalance = 0  # 股份余额
    volAvailable = 0  # 股份可用
    volTradeFrozen = 0  # 股份交易冻结数
    volOtd=0 #在途可用。
    volFrozen=0 #股份异常冻结数
    volUntrade=0 #非流通股份

    marketVal = 0  # 市值
    marketPrice = 0  # 市价
    costPrice=0 #持仓成本

    entryTime = None  # 更新时间  yyyy-MM-dd HH:mm:ss:SSS

    def changeFormat(self):
        self.volAvailable=int(self.volAvailable)
        self.volTradeFrozen=int(self.volTradeFrozen)
        self.volOtd=int(self.volOtd)
        self.volFrozen=int(self.volFrozen)
        self.volUntrade=int(self.volUntrade)
        self.market=self.market.encode("utf-8")

        self.marketVal=float(self.marketVal)
        self.marketPrice=float(self.marketPrice)

        volBalance=self.volAvailable\
                       +self.volOtd\
                       +self.volTradeFrozen\
                       +self.volFrozen\
                       +self.volUntrade

        self.volBalance=volBalance
        self.marketVal=self.volBalance*self.marketPrice
        return self



    def getTableName(self):
        pass

    def getTableFieldMap(self):
        pass

    def __str__(self):
        descDict = self.__dict__
        return """Share-----{desc}""".format(
            desc=",".join(
                ["{key}:{val}".format(key=key, val=val.encode("utf-8") if isinstance(val, unicode) else val) for
                 key, val in descDict.items()])
        )